package jdir.dialog;

import static jdir.util.LogUtil.begin;
import static jdir.util.LogUtil.end;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JSplitPane;

import jdir.Control;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * This class represents the main JDir dialog in which the lion's share of 
 * userinteraction will take place.
 * @author Marco Peroverde
 */
@SuppressWarnings("unused")
public class JDirMainDlg extends JFrame
{
	private static final long	serialVersionUID	= -6628923500320680281L;
	
	private static Log				LOG		= LogFactory.getLog(JDirMainDlg.class);
	private static Boolean			DEBUG	= LOG.isDebugEnabled();	
	private static Boolean			TRACE	= LOG.isTraceEnabled();
	private static int				WIDTH   = 640;
	private static int				HEIGTH  = 700;
	private static int				DIVSIZE = 7; //Size for Divider
	
	//Dialogelements	...
	private Control control;
	private Container contentPane;
	
	private JSplitPane fileListSplitter;
	private JSplitPane mainSplitter;
	
	private UserButtonsPanel userButtonsPanel;
		
	private FileListPanel fileListPanelLeft;
	private FileListPanel fileListPanelRight;
	//...	Dialogelements
	
	
	public JDirMainDlg()
	{
		if(DEBUG)
			begin(LOG, "");
		this.control = Control.getInstance();
		this.setTitle("JDir");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new BorderLayout());
		this.setSize(WIDTH+DIVSIZE,HEIGTH);
		Container contentPane = this.getContentPane();
		int fileListHeight = (int)Math.round(((double)2/3)*this.getHeight());
		int fileListWidth = (int)(this.getWidth()*0.5);	
		
		
		fileListPanelLeft = new FileListPanel(true, fileListHeight, fileListWidth, this);
		fileListPanelRight = new FileListPanel(false, fileListHeight, fileListWidth, this);
		
		fileListSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, fileListPanelLeft, fileListPanelRight);
		fileListSplitter.setDividerSize(DIVSIZE);
		fileListSplitter.setDividerLocation((this.getWidth()/2)); //Set panel to half of fram width
		
		int lheightOfScrollers = (int)Math.round(((double)2/3)*this.getHeight()); //Größe der FileListen auf 2/3 Dlghöhe setzen
		fileListSplitter.setPreferredSize(new Dimension(this.getWidth(), lheightOfScrollers));
		
		userButtonsPanel = new UserButtonsPanel(this);		
		mainSplitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, fileListSplitter, userButtonsPanel);
		mainSplitter.setDividerSize(DIVSIZE);
		contentPane.add(mainSplitter, BorderLayout.CENTER);
		
		this.pack();
		this.setResizable(true);
		this.setVisible(true);	
		
		if(DEBUG)
			end(LOG, "");
	}
	
	/**
	 * 
	 * @return
	 */
	public boolean hasLeftSideFocus()
	{
		return fileListPanelLeft.hasFocus();
	}

	public FileListPanel getFileListPanelLeft() {
		return fileListPanelLeft;
	}

	public FileListPanel getFileListPanelRight() {
		return fileListPanelRight;
	}

}
